﻿#include "ReadMEMSDataCodec_Client.h"

#include "TcpCodec.h"

#include <qdebug.h>

ReadMEMSDataCodec_Client::ReadMEMSDataCodec_Client(QObject *parent) : QObject(parent)
{
  funMap.insert(ReadAll,&ReadMEMSDataCodec_Client::decode_readAll);
  funMap.insert(ReadByDateTime,&ReadMEMSDataCodec_Client::decode_ReadByDateTime);
}

void ReadMEMSDataCodec_Client::code(uchar readType,QByteArray data)
{
  data.prepend(readType);
//  tcpCodec->code(TcpCodec::ReadSensorData,data);
}

void ReadMEMSDataCodec_Client::decode(QByteArray data)
{
  void(ReadMEMSDataCodec_Client::*fun)(QByteArray)=funMap.value(data[0],Q_NULLPTR);
  if(Q_NULLPTR!=fun)
    {
      (this->*fun)(data.mid(1));
    }
}

void ReadMEMSDataCodec_Client::readAll()
{
  code(ReadAll);
}


void ReadMEMSDataCodec_Client::readByTime(QDateTime begin,QDateTime end)
{}

void ReadMEMSDataCodec_Client::decode_readAll(QByteArray data)
{
  emit signal_readAll(MEMSData::fromByteArrayToList(data));
}

void ReadMEMSDataCodec_Client::decode_ReadByDateTime(QByteArray data)
{
  //  QVector<MEMSData> list=
}

TcpCodec* ReadMEMSDataCodec_Client::getTcpCodec()
{
  return tcpCodec;
}

void ReadMEMSDataCodec_Client::setTcpCodec(TcpCodec* tcpCodec)
{
  this->tcpCodec=tcpCodec;
  printInjection(this,tcpCodec);
}

void ReadMEMSDataCodec_Client::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setTcpCodec(ReadMEMSDataCodec_Client::getObjFromMap<TcpCodec>(objMap));
}
